<?php

namespace api\modules\backend\models;

use \yii;
use \yii\db\ActiveRecord;

/**
 * Account Model
 *
 */
class Account extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%admin}}';
    }

    /**
     * Define rules for validation
     */
    public function rules()
    {
        return [];
    }

    /**
     * 生成ApiToken
     * @throws yii\base\Exception
     */
    public function generateApiToken()
    {
        $this->api_token = Yii::$app->security->generateRandomString() . '_' . time();//获取token
        $expire = Yii::$app->params['user.apiTokenExpire'];
        $this->api_token_expire = time() + $expire;//设置token过期时间
        $this->update_time = time();//登录时间
        $this->last_ip = Yii::$app->request->getUserIP();
    }
}
